<?php

use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;

use Destroyer\Admin;
use Destroyer\Http\Controllers\TokenController;
use Destroyer\Http\Controllers\ProfileController;

use Destroyer\Http\Controllers\UserController;
use Destroyer\Http\Controllers\MenuController;
use Destroyer\Http\Controllers\RoleController;

use Destroyer\Http\Controllers\DictDataController;



Route::get('/', function (Request $request) {
    return [
        'routes' => array_column(Route::getRoutes()->getRoutes(), 'uri')
    ];
});



// 登录
Route::post('/token', [TokenController::class, 'store']);

// 退出
Route::delete('/token', [TokenController::class, 'destroy']);



Route::prefix('system')->name('admin.system.')->group(function () {
    Route::get('/timezone', function (Request $request) {
        $timezone = array_map(function($timezone){
            return [
                'label' => $timezone,
                'value' => $timezone,
            ];
        }, timezone_identifiers_list());
        return response()->admin($timezone);
    });



    


    // 我的菜單
    Route::get('/nav', NavController::class);


    // 個人資料
    Route::controller(ProfileController::class)->group(function () {
        Route::get('/profile', 'show');
        Route::put('/profile', 'update');
        Route::post('/profile', 'store');
    });



    // 系統用戶
    Route::apiResource('user', UserController::class)->parameters(['user' => 'id']);

    // 菜单管理
    Route::apiResource('menu', MenuController::class)->parameters(['menu' => 'id']);

    // 角色管理
    Route::get('role/select', [RoleController::class, 'select']);
    Route::apiResource('role', RoleController::class)->parameters(['role' => 'id']);

    // 数据字典
    Route::get('/dict-data/list', [DictDataController::class, 'list']); 
    Route::apiResource('dict-type', DictTypeController::class)->parameters(['dict-type' => 'id']);
    Route::apiResource('dict-data', DictDataController::class)->parameters(['dict-data' => 'id']);

});


